﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Xiaozilang_Ordering_System
{
    public partial class denglu : Form
    {
        public static int Judge = 0;
        public static string tel;//账号
        public static string Name1;//账号名字
        public static string address;//账号地址
        public static string imagelj;//头像
        public static string Money;//客户余额
        public static string pentPWd;//客户支付密码
        public static string ID;//编号
        public denglu()
        {
            InitializeComponent();
            textBox1.Enter += new EventHandler(textBox1_Enter);
            textBox1.Leave += new EventHandler(textBox1_leave);
            textBox2.Enter += new EventHandler(textBox2_Enter);
            textBox2.Leave += new EventHandler(textBox2_leave);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //创建实例化对象
            Registration_interface Reg = new Registration_interface();
            //转接商家注册界面
            Reg.Show();
        }
        private void textBox1_Enter(object sender,EventArgs e) 
        {
            if (textBox1.Text == "手机账号")
            {
                textBox1.Text = "";
            }

        }
        private void textBox1_leave(object sender, EventArgs e) 
        {
            if (textBox1.Text == "")
            {
                textBox1.Text = "手机账号";
            }
        }

        private void textBox2_Enter(object sender, EventArgs e)
        {
            if (textBox2.Text == "密码")
            {
                textBox2.Text = "";
            }
        }
        private void textBox2_leave(object sender, EventArgs e)
        {
            if (textBox2.Text == "")
            {
                textBox2.Text = "密码";
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            SqlDataReader reader = null;
            string pwd = null;
            string sql ;
            //非空验证
            if (textBox1.Text!="手机账号"&&textBox2.Text!="密码")
            {
               
                try
                {
                    //商家登录
                    if (radioButton1.Checked)
                    {
                        Judge = 0;
                        sql = "select *from Business where BStel='" + textBox1.Text + "' and BSpwd='" + textBox2.Text + "'";
                        reader = DBHelper.Select(sql);
                        //登录获取全部信息
                        while (reader.Read())
                        {
                           
                            tel = reader["BStel"].ToString();
                            pwd = reader["BSpwd"].ToString();
                            Name1 = reader["BSname"].ToString();
                            address = reader["BSaddress"].ToString();
                            Money = reader["BSMoney"].ToString();
                            imagelj = reader["BSimage"].ToString();
                            ID = reader["BSID"].ToString();
                        }

                    }
                    if (radioButton2.Checked)
                    {
                        Judge = 1;
                        sql = "select *from User1 where UStel='" + textBox1.Text + "' and USpwd='" + textBox2.Text + "'";
                        reader = DBHelper.Select(sql);
                        //登录获取全部信息
                        while (reader.Read())
                        {
                            tel = reader["UStel"].ToString();
                            pwd = reader["USpwd"].ToString();
                            Name1 = reader["USname"].ToString();
                            address = reader["USaddress"].ToString();
                            ID = reader["userID"].ToString();
                            Pay.zfPassword = reader["pentPwd"].ToString();
                            imagelj = reader["USimage"].ToString();
                            Money = reader["USMoney"].ToString();
                        }
                        
                    }
                    reader.Close();
                    if (tel==null)
                    {
                        MessageBox.Show("账号或密码错误！");
                    }
                   
                    if (tel==textBox1.Text&&pwd==textBox2.Text) 
                    {
                        MessageBox.Show("欢迎使用小次郎点餐");
                        Shopping_Cart.UserJudge = ID;
                        //判断账号所属来打开不同的界面
                        switch (Judge)
                        {
                            case 0:
                                Business f2 = new Business();
                                f2.Show();
                                break;
                            case 1:
                                client cl = new client();
                                cl.Show();
                                break;
                        }
                        Hide();
                       
                    }
                    
                }catch(Exception ex)
                {
                    MessageBox.Show("错误{0}",ex.Message);
                }
            }
            else 
            {
                MessageBox.Show("信息输入不全，请重新输入！");
            }
        }
        private void button3_Click(object sender, EventArgs e)
        {
            losepwd los = new losepwd();
            los.Show();
        }

        private void denglu_Load(object sender, EventArgs e)
        {
            //文字背景透明
            label1.BackColor = Color.Transparent;
            label2.BackColor = Color.Transparent;
            radioButton1.BackColor = Color.Transparent;
            radioButton2.BackColor = Color.Transparent;
            checkBox1.BackColor = Color.Transparent;
        }

        private void denglu_FormClosing(object sender, FormClosingEventArgs e)
        {
            Application.Exit();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
        }

        private void checkBox1_MouseDown(object sender, MouseEventArgs e)
        {
            if (checkBox1.Checked) 
            {
                button2.Enabled = false;
            }
            else
            {
                button2.Enabled = true;
            }
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }
    }
}
